# Building test package:
#
#     apt-get install libssl-dev libmariadbclient-dev php5 perl \
#         coreutils realpath libjansson-dev openjdk-7-jdk
#     pip install JayDeBeApi


# Backend labes:
#     REPL_BACKEND
#     GALERA_BACKEND
#     EXTERN_BACKEND
#     CS_BACKEND
#     BREAKS_REPL
#     BREAKS_GALERA
set(CTEST_BUILD_NAME "${BUILDNAME}")
set(TEST_DEFINITIONS "" CACHE INTERNAL "")

# GCC12 has problems with false positives in std::regex
add_definitions(-Wno-maybe-uninitialized)

# utilities.cmake contains all helper functions and extra tools
include(utilities.cmake)

include_directories(maxtest/include)
# Include the CDC connector headers
include_directories(${CMAKE_SOURCE_DIR}/connectors/cdc-connector)

# Tool used to check backend state
add_test_executable_notest(check_backend.cc check_backend check_backend LABELS CONFIG REPL_BACKEND GALERA_BACKEND)

# Builds MaxScale from source on the test machine itself. Called by gcov builds.
add_test_executable_notest(gcov_start.cc gcov_start minimal LABELS CONFIG)
# Collects the gcov results and stores them.
add_test_executable_notest(gcov_stop.cc gcov_stop minimal LABELS CONFIG)

# Test configurations that should fail to start.
add_test_executable(bad_configuration.cc bad_configuration minimal LABELS LIGHT CONFIG REPL_BACKEND)

add_subdirectory(cdc_datatypes)

############################################
# BEGIN: Normal tests                      #
############################################

add_subdirectory(mariadbmonitor)
add_subdirectory(pinloki)
add_subdirectory(config_sync)
add_subdirectory(schemarouter)
add_subdirectory(filters)
add_subdirectory(rworker)
add_subdirectory(connectors)
add_subdirectory(sql_api)

# MXS-1506: Delayed query retry
# https://jira.mariadb.org/browse/MXS-1506
add_test_executable(mxs1506_delayed_retry.cc mxs1506_delayed_retry mxs1506_delayed_retry LABELS readwritesplit REPL_BACKEND)

# MXS-1506: Delayed retry without master
# https://jira.mariadb.org/browse/MXS-1506
add_test_executable(mxs1506_no_master.cc mxs1506_no_master mxs1506_delayed_retry LABELS readwritesplit REPL_BACKEND)

# MXS-1507: Transaction replay
# https://jira.mariadb.org/browse/MXS-1507
add_test_executable(mxs1507_trx_replay.cc mxs1507_trx_replay mxs1507_trx_replay LABELS readwritesplit REPL_BACKEND)

# MXS-1507: Inconsistent transactions
# https://jira.mariadb.org/browse/MXS-1507
add_test_executable(mxs1507_inconsistent_trx.cc mxs1507_inconsistent_trx mxs1507_trx_replay LABELS readwritesplit REPL_BACKEND)

# MXS-1507: Transaction migration
# https://jira.mariadb.org/browse/MXS-1507
add_test_executable(mxs1507_migrate_trx.cc mxs1507_migrate_trx mxs1507_trx_replay LABELS readwritesplit REPL_BACKEND)

# MXS-1507: Transaction replay
# https://jira.mariadb.org/browse/MXS-1507
add_test_executable(mxs1507_trx_stress.cc mxs1507_trx_stress mxs1507_trx_stress LABELS readwritesplit REPL_BACKEND)

# MXS-2187: Multiple transaction replays
# https://jira.mariadb.org/browse/MXS-1507
add_test_executable(mxs2187_multi_replay.cc mxs2187_multi_replay mxs2187_multi_replay LABELS readwritesplit REPL_BACKEND)

# MXS-1778: Use GTID from OK packets for consistent reads
# https://jira.mariadb.org/browse/MXS-1776
add_test_executable(mxs1778_causal_reads.cc mxs1778_causal_reads mxs1778_causal_reads LABELS readwritesplit REPL_BACKEND)

# MXS-2443: Test causal_reads=global
# https://jira.mariadb.org/browse/MXS-2443
add_test_executable(mxs2443_global_causal_reads.cc mxs2443_global_causal_reads mxs2443_global_causal_reads LABELS readwritesplit REPL_BACKEND)

# MXS-3416: Unexpected OK packet with causal_reads=global
# https://jira.mariadb.org/browse/MXS-3416
add_test_executable(mxs3416_causal_reads_extra_packet.cc mxs3416_causal_reads_extra_packet mxs2443_global_causal_reads LABELS readwritesplit REPL_BACKEND)

# MXS-1720: Test causal_reads=fast
# https://jira.mariadb.org/browse/MXS-1720
# Also covers MXS-4122: causal_reads=fast_global
add_test_executable(mxs1720_fast_causal_reads.cc mxs1720_fast_causal_reads mxs1720_fast_causal_reads LABELS readwritesplit REPL_BACKEND)

# MXS-3499: Prepared statement support for causal_reads
# https://jira.mariadb.org/browse/MXS-3499
add_test_executable(mxs3499_causal_reads_ps.cc mxs3499_causal_reads_ps mxs3499_causal_reads_ps LABELS readwritesplit REPL_BACKEND)

# MXS-3663: Universal causal_reads
add_test_executable(mxs3663_universal_causal_reads.cc mxs3663_universal_causal_reads mxs3663_universal_causal_reads LABELS REPL_BACKEND readwritesplit)

# MXS-4123: Fast universal causal reads
add_test_derived(mxs4123_fast_universal mxs3663_universal_causal_reads mxs4123_fast_universal LABELS readwritesplit REPL_BACKEND)

# MXS-1961: Standalone master loses master status
# https://jira.mariadb.org/browse/MXS-1961
add_test_executable(mxs1961_standalone_rejoin.cc mxs1961_standalone_rejoin mxs1961_standalone_rejoin LABELS REPL_BACKEND)

# MXS-2456: Cap transaction replay attempts
add_test_executable(mxs2456_trx_replay_cap.cc mxs2456_trx_replay_cap mxs2456_trx_replay_cap LABELS readwritesplit REPL_BACKEND)

# MXS-2512: Enable transaction replay for additional rollback errors.
add_test_executable(mxs2512_trx_replay_rollback.cc mxs2512_trx_replay_rollback mxs2512_trx_replay_rollback LABELS readwritesplit REPL_BACKEND)

# MXS-2785: Binlogfilter database rewrite test
add_test_executable(mxs2785_binlogfilter_rewrite.cc mxs2785_binlogfilter_rewrite mxs2785_binlogfilter_rewrite LABELS binlogfilter REPL_BACKEND)

# KafkaCDC tests
add_subdirectory(kafka)

if(BUILD_NOSQL)
  add_subdirectory(nosqlprotocol)
endif()

# Routing sanity check. Also acts as the regression test case the following issues:
#
# MXS-127
# MXS-47
# MXS-682
# MXS-957
# MXS-1786
# MXS-3229
# MXS-3915
# MXS-4269
add_test_executable(sanity_check.cc sanity_check replication LABELS readwritesplit LIGHT REPL_BACKEND)

# Repeatedly connect to maxscale while the backends reject all connections, expect no crash
add_test_executable(backend_auth_fail.cc backend_auth_fail replication LABELS readconnroute REPL_BACKEND)

# Test wildcard in user host name (user@127.%.%.%). Also test MXS-3172 escaped wildcard in database grant and
# MXS-3323 non-escaped wildcard.
add_test_executable(auth_wchost.cc auth_wchost auth_wchost LABELS MySQLAuth LIGHT REPL_BACKEND)

# Regression case for the bug "Routing Hints route to server sometimes doesn't work"
add_test_executable(rhint_basic.cc rhint_basic rhint_basic LABELS readwritesplit hintfilter REPL_BACKEND)

# Regression case for the bugs "malformed hints cause crash"
add_test_executable(rhint_crash.cc rhint_crash hints LABELS readwritesplit hintfilter REPL_BACKEND)

# Regression case for the bug "The end comment tag in hints isn't properly detected"
add_test_executable(rhint_comment.cc rhint_comment hints LABELS readwritesplit hintfilter REPL_BACKEND)

# MXS-2838: Hints in prepared statements
add_test_executable(mxs2838_ps_hints.cc mxs2838_ps_hints mxs2838_ps_hints LABELS hintfilter REPL_BACKEND)

# MaxGUI test
add_test_executable(test_maxgui.cc test_maxgui test_maxgui LABELS maxgui REPL_BACKEND)

# Checks "SELECT * INTO OUTFILE" and "LOAD DATA LOCAL INFILE"
add_test_executable(rwsplit_infile_outfile.cc rwsplit_infile_outfile replication LABELS readwritesplit REPL_BACKEND)

# Regression case for the bug "'Current no. of conns' not going down"
add_test_executable(router_conn_num.cc router_conn_num replication LABELS readwritesplit readconnroute maxscale REPL_BACKEND)

# Regression: Crash if no slave available
add_test_executable(router_slaves_blocked.cc router_slaves_blocked replication LABELS readwritesplit REPL_BACKEND)

# Regression case for the bug ""Different error messages from MariaDB and Maxscale"
add_test_executable(error_messages.cc error_messages replication LABELS MySQLAuth REPL_BACKEND)

# Regression case for the bug "Wrong error message for Access denied error"
add_test_script(bug562.sh bug562.sh replication LABELS MySQLAuth REPL_BACKEND)

# Regression case for the bug "Wrong charset settings"
add_test_script(bug564.sh bug564.sh replication LABELS MySQLProtocol REPL_BACKEND)

# Regression case for the bug "Clients CLIENT_FOUND_ROWS setting is ignored by maxscale"
add_test_executable(mariadb_client_found_rows.cc mariadb_client_found_rows replication LABELS MySQLProtocol REPL_BACKEND)

# Regression case for the bug "Crash if files from /dev/shm/ removed"
add_test_script(bug567.sh bug567.sh bug567 LABELS maxscale REPL_BACKEND)

# Regression case for the bug "Using regex filter hangs MaxScale"
add_test_executable(regexf_replace.cc regexf_replace regexf_replace LABELS regexfilter REPL_BACKEND)

# Attempt to use GRANT with wrong IP, expect no crash or hangs
add_test_executable(auth_fail_crash.cc auth_fail_crash replication LABELS readwritesplit REPL_BACKEND)

# Regression cases for the bug "Hint filter don't work if listed before regex filter in configuration file"
# (different filter sequence and configuration, but the same test, see .cnf for details)
add_test_derived(bug585 bug587 bug585 LABELS regexfilter REPL_BACKEND)
add_test_executable(bug587.cc bug587 bug587 LABELS regexfilter hintfilter REPL_BACKEND)
add_test_derived(bug587_1 bug587 bug587_1 LABELS regexfilter hintfilter REPL_BACKEND)

# Tries to connect Maxscale when all slaves stopped
add_test_executable(auth_users_from_master.cc auth_users_from_master replication LABELS MySQLAuth readwritesplit REPL_BACKEND)

# Tries to do change user in the loop, checks that autorization is still ok
add_test_executable(auth_change_user_loop.cc auth_change_user_loop auth_change_user_loop LABELS MySQLAuth MySQLProtocol REPL_BACKEND)

# Simple test with enable_root_user=true
add_test_executable(auth_enable_root.cc auth_enable_root auth_enable_root LABELS MySQLAuth MySQLProtocol REPL_BACKEND)

# Regression case for the bug "Crash when user define with old password style (before 4.1 protocol)"
add_test_executable(auth_old_pw.cc auth_old_pw replication LABELS MySQLAuth MySQLProtocol REPL_BACKEND)

# Crash when host name for some user in mysql.user is very long
add_test_executable(auth_long_hostname.cc auth_long_hostname replication LABELS MySQLAuth MySQLProtocol REPL_BACKEND)

# Block backends (master or all slaves) and tries to connect Maxscale
add_test_executable(no_backends_crash.cc no_backends_crash replication LABELS readwritesplit readconnroute maxscale REPL_BACKEND)

# Block all backends
add_test_executable(startup_fail_no_servers.cc startup_fail_no_servers startup_fail_no_servers LABELS readwritesplit readconnroute maxscale REPL_BACKEND)

# Bad TEE filter configuration
add_test_executable(teef_no_master.cc teef_no_master teef_no_master LABELS MySQLAuth MySQLProtocol REPL_BACKEND)

# Wrong processing of 'SET GLOBAL sql_mode="ANSI"'
add_test_executable(auth_sqlmode_ansi.cc auth_sqlmode_ansi auth_sqlmode_ansi LABELS MySQLAuth REPL_BACKEND)

# Prepared statement from PHP application
add_test_executable(rwsplit_php_stmt.cc rwsplit_php_stmt replication LABELS readwritesplit LIGHT REPL_BACKEND)

# Regression case for the bug "Regex filter and shorter than original replacement queries MaxScale" (crash)
add_test_executable(regexf_replace_crash.cc regexf_replace_crash regexf_replace_crash LABELS regexfilter REPL_BACKEND)

# Test MariaDB 10.2 bulk inserts
add_test_executable(bulk_insert.cc bulk_insert bulk_insert LABELS MySQLProtocol REPL_BACKEND 10.2)

# Tests for the CCRFilter module
add_test_executable(ccrfilter.cc ccrfilter_test ccrfilter LABELS ccrfilter LIGHT REPL_BACKEND)
add_test_executable(ccrfilter_global.cc ccrfilter_global_test ccrfilter_global LABELS ccrfilter LIGHT REPL_BACKEND)

# Tries to reconfigure replication setup to use another node as a Master
add_test_executable(change_master_during_session.cc change_master_during_session replication LABELS readwritesplit mysqlmon REPL_BACKEND)

# Tries to connect to non existing DB, expects no crash
add_test_executable(connect_to_nonexisting_db.cc connect_to_nonexisting_db replication LABELS MySQLAuth MySQLProtoco LIGHT REPL_BACKEND)

# check if max_connections parameter works
add_test_executable(connection_limit.cc connection_limit connection_limit LABELS maxscale LIGHT REPL_BACKEND)

# Tries to open to many connections, expect no crash
add_test_executable(crash_out_of_files.cc crash_out_of_files load LABELS maxscale HEAVY REPL_BACKEND)

# Tries INSERTs with size close to 0x0ffffff * N
add_test_executable(different_size_rwsplit.cc different_size_rwsplit replication LABELS readwritesplit HEAVY REPL_BACKEND)

# Tries to use 'maxkeys', 'maxpasswrd'
add_test_executable(encrypted_passwords.cc encrypted_passwords replication LABELS maxscale LIGHT REPL_BACKEND)

# Basic MaxCtrl test. Also covers the following bugs:
# MXS-3697: ENOENT: no such file or directory, stat '/~/.maxctrl.cnf' when running commands from the root directory.
# MXS-4169: Listeners wrongly require ssl_ca_cert during creation
add_test_executable(maxctrl_basic.cc maxctrl_basic maxctrl_basic LABELS maxctrl REPL_BACKEND)

# MXS-2167: Monitors should be able to use extra_port
add_test_executable(mxs2167_extra_port.cc mxs2167_extra_port mxs2167_extra_port LABELS REPL_BACKEND)

# Test KILL QUERY functionality
add_test_executable(kill_query.cc kill_query kill_query LABELS REPL_BACKEND)

# MXS-2250: DESCRIBE on temporary table should work.
add_test_executable(mxs2250_describe_temp_table.cc mxs2250_describe_temp_table mxs2250_describe_temp_table LABELS REPL_BACKEND)

# Test monitor state change events when manually clearing server bits
add_test_executable(false_monitor_state_change.cc false_monitor_state_change replication LABELS mysqlmon REPL_BACKEND)

# Block and unblock Master and check that Maxscale survived
add_test_executable(kill_master.cc kill_master replication LABELS readwritesplit LIGHT REPL_BACKEND)

# Check load balancing
add_test_executable(load_balancing.cc load_balancing load LABELS readwritesplit LIGHT REPL_BACKEND)

# Check load balancing parameters with 10 persistent connections
add_test_derived(load_balancing_pers10 load_balancing load_pers10 LABELS readwritesplit HEAVY REPL_BACKEND)

# Test with extremely big blob inserting
add_test_executable(longblob.cc longblob longblob LABELS readwritesplit readconnroute REPL_BACKEND)
add_test_derived(longblob_ssl longblob longblob LABELS readwritesplit readconnroute BACKEND_SSL LISTENER_SSL
        REPL_BACKEND)

# Retry reads with persistent connections
add_test_executable(mxs1323_retry_read.cc mxs1323_retry_read mxs1323 LABELS readwritesplit LIGHT REPL_BACKEND)
add_test_executable(mxs1323_stress.cc mxs1323_stress mxs1323 LABELS readwritesplit REPL_BACKEND)

# A set of MariaDB server tests executed against Maxscale RWSplit
add_test_script(mariadb_tests_hartmut.sh mariadb_tests_hartmut.sh replication LABELS readwritesplit REPL_BACKEND)

# Checks tha Maxscale processis running as 'maxscale' user
add_test_executable(maxscale_process_user.cc maxscale_process_user replication LABELS maxscale LIGHT REPL_BACKEND)

# Regression case for the bug "Two monitors loaded at the same time result into not working installation"
add_test_executable(mxs118.cc mxs118 mxs118 LABELS maxscale LIGHT REPL_BACKEND)

# Regression case for the bug "SELECT INTO OUTFILE query succeeds even if backed fails"
add_test_executable(mxs280_select_outfile.cc mxs280_select_outfile replication LABELS readwritesplit REPL_BACKEND)

# Testing of the master replacement feature
add_test_executable(mxs359_master_switch.cc mxs359_master_switch mxs359_master_switch LABELS readwritesplit REPL_BACKEND)

# Test read-only connections with master replacement
add_test_executable(mxs359_read_only.cc mxs359_read_only mxs359_read_only LABELS readwritesplit REPL_BACKEND)

# Test master_failure_mode=error_on_write and master replacement
add_test_executable(mxs359_error_on_write.cc mxs359_error_on_write mxs359_error_on_write LABELS readwritesplit REPL_BACKEND)

# Binary protocol prepared statement tests (also tests MXS-2266)
add_test_executable(binary_ps.cc binary_ps replication LABELS readwritesplit LIGHT REPL_BACKEND)
add_test_executable(binary_ps_cursor.cc binary_ps_cursor replication LABELS readwritesplit LIGHT REPL_BACKEND)

# Creates and closes a lot of connections, checks that 'list servers' shows 0 connections at the end
add_test_executable(mxs321.cc mxs321 replication LABELS maxscale readwritesplit REPL_BACKEND)

# Load huge file with 'LOAD DATA LOCAL INFILE'. MXS-365.
add_test_executable_ex(NAME load_data_local_infile SOURCE load_data_local_infile.cc
        CONFIG load_data_local_infile.cnf VMS repl_backend)
# SSL-version of load_data_local_infile
add_test_executable_ex(NAME load_data_local_infile_ssl ORIG_NAME load_data_local_infile
        CONFIG load_data_local_infile.cnf VMS repl_backend LABELS BACKEND_SSL LISTENER_SSL)

# Test users with different level privileges: database, table, column and procedure.
# MXS-37, MXS-3303, MXS-1958, MXS-3630, MXS-4093
add_test_executable_ex(NAME client_privileges SOURCE client_privileges.cc CONFIG client_privileges.cnf
        VMS repl_backend)

# Open connection, execute 'change user', close connection in the loop
add_test_executable(mxs548_short_session_change_user.cc mxs548_short_session_change_user mxs548 LABELS MySQLProtocol readwritesplit REPL_BACKEND)

# Playing with blocking and unblocking Master under load
add_test_executable(mxs559_block_master.cc mxs559_block_master mxs559 LABELS readwritesplit REPL_BACKEND)

# Regression case for the bug "MaxScale fails to start silently if config file is not readable"
add_test_executable(mxs621_unreadable_cnf.cc mxs621_unreadable_cnf replication LABELS maxscale REPL_BACKEND)

# playing with 'restart service' and restart Maxscale under load
add_test_executable(mxs657_restart.cc mxs657_restart replication LABELS maxscale HEAVY REPL_BACKEND)
add_test_executable(mxs657_restart_service.cc mxs657_restart_service replication LABELS maxscale REPL_BACKEND)

# Connect using different default database using user with database and table level grants
add_test_executable(mxs716.cc mxs716 replication LABELS MySQLAuth LIGHT REPL_BACKEND)

# MaxScale configuration check functionality test (maxscale -c)
add_test_executable(mxs722.cc mxs722 mxs722 LABELS maxscale LIGHT REPL_BACKEND)

# Checks "Current no. of conns" output after long blob inserting
add_test_executable(mxs812_1.cc mxs812_1 longblob LABELS readwritesplit REPL_BACKEND)

# Checks "Current no. of conns" output after long blob inserting
add_test_executable(mxs812_2.cc mxs812_2 replication LABELS readwritesplit REPL_BACKEND)

# Tests maxpasswd
add_test_executable(mxs822_maxpasswd.cc mxs822_maxpasswd maxpasswd LABELS maxscale REPL_BACKEND)

# Do only SELECTS during time > wait_timeout and then do INSERT
add_test_executable(mxs827_write_timeout.cc mxs827_write_timeout mxs827_write_timeout LABELS readwritesplit REPL_BACKEND)

# MXS-872: MaxScale doesn't understand roles
# https://jira.mariadb.org/browse/MXS-872
add_test_executable(mxs872_roles.cc mxs872_roles replication LABELS REPL_BACKEND)

# MXS-1947: Composite roles are not supported
# https://jira.mariadb.org/browse/MXS-1947
add_test_executable(mxs1947_composite_roles.cc mxs1947_composite_roles replication LABELS REPL_BACKEND)

# Block and unblock first and second slaves and check that they are recovered
add_test_executable(mxs874_slave_recovery.cc mxs874_slave_recovery mxs874 LABELS readwritesplit REPL_BACKEND)

# A set of dynamic configuration tests
# Server removal test
add_test_executable(mxs922_bad_server.cc mxs922_bad_server mxs922 LABELS maxscale REPL_BACKEND)

# Server creation test
add_test_executable(mxs922_server.cc mxs922_server mxs922_base LABELS maxscale REPL_BACKEND)

# Monitor creation test
add_test_executable(mxs922_monitor.cc mxs922_monitor mxs922_base LABELS maxscale REPL_BACKEND)

# Double creation of listeners, expect no crash
add_test_executable(mxs922_double_listener.cc mxs922_double_listener mxs922_base LABELS maxscale REPL_BACKEND)

# Test persisting of configuration changes
add_test_executable(mxs922_restart.cc mxs922_restart mxs922 LABELS maxscale REPL_BACKEND)

# Server scaling test
add_test_executable(mxs922_scaling.cc mxs922_scaling mxs922_base LABELS maxscale REPL_BACKEND)

# Dynamic listener SSL test
add_test_executable(mxs922_listener_ssl.cc mxs922_listener_ssl mxs922_base LABELS maxscale BACKEND_SSL REPL_BACKEND)

# Alter routers at runtime
add_test_executable(alter_router.cc alter_router alter_router LABELS maxscale REPL_BACKEND)

# Test of MaxRows filter
add_test_executable(mxs1071_maxrows.cc mxs1071_maxrows maxrows LABELS maxrowsfilter REPL_BACKEND)

# Test of Masking filter
add_test_executable(masking_mysqltest.cc masking_mysqltest masking_mysqltest LABELS maskingfilter REPL_BACKEND)

add_test_executable(masking_user.cc masking_user masking_mysqltest LABELS maskingfilter REPL_BACKEND)

add_test_executable(masking_auto_firewall.cc masking_auto_firewall masking_auto_firewall LABELS masking REPL_BACKEND)

# Test of Cache filter - basics
add_test_executable(cache_basic.cc cache_basic cache_basic LABELS cachefilter REPL_BACKEND)

# Test of Cache filter - runtime configuration
add_test_executable(cache_runtime.cc cache_runtime cache_runtime LABELS cachefilter REPL_BACKEND)

# Test of Cache filter - ttl runtime configuration
add_test_executable(cache_runtime_ttl.cc cache_runtime_ttl cache_runtime_ttl LABELS cachefilter REPL_BACKEND)

# Test of Cache filter - invalidate
add_test_executable(cache_invalidate.cc cache_invalidate cache_invalidate LABELS cachefilter REPL_BACKEND)

# Test of Cache filter - users
add_test_executable(cache_users.cc cache_users cache_users LABELS cachefilter REPL_BACKEND)

# Test of Cache filter - distributed storages, transparently taken in and out of use
add_test_executable(cache_distributed.cc cache_distributed cache_distributed LABELS cachefilter REPL_BACKEND)

# Test of Cache filter - redis authentication
add_test_executable(cache_redis_security.cc cache_redis_security cache_redis_security LABELS cachefilter REPL_BACKEND)

# Test of Cache filter - redis ssl
add_test_executable(cache_redis_ssl.cc cache_redis_ssl cache_redis_ssl LABELS cachefilter REPL_BACKEND)

# Test of Cache filter - runtime configuration change
add_test_executable(cache_runtime_config.cc cache_runtime_config cache_runtime_config LABELS cachefilter REPL_BACKEND)

# Test of Cache bug MXS-3694
add_test_executable(mxs3694_cache.cc mxs3694_cache mxs3694_cache LABELS cachefilter REPL_BACKEND)

# Test of Cache bug MXS-3778
add_test_executable(mxs3778_cache.cc mxs3778_cache mxs3778_cache LABELS cachefilter REPL_BACKEND)

# Set utf8mb4 in the backend and restart Maxscale
add_test_executable(mxs951_utfmb4.cc mxs951_utfmb4 replication LABELS REPL_BACKEND)

# Proxy protocol test. Also MXS-3003: Inbound proxy protocol.
add_test_executable(proxy_protocol.cc proxy_protocol proxy_protocol LABELS MySQLAuth MySQLProtocol REPL_BACKEND)

# MXS-3342: Crash with proxy protocol and persistent connections
add_test_executable(mxs3342_proxy_protocol_pool.cc mxs3342_proxy_protocol_pool mxs3342_proxy_protocol_pool LABELS REPL_BACKEND)

# Regression case for the bug "Defunct processes after maxscale have executed script during failover"
add_test_executable(mxs1045.cc mxs1045 mxs1045 LABELS maxscale REPL_BACKEND)

# MXS-1123: connect_timeout setting causes frequent disconnects
# https://jira.mariadb.org/browse/MXS-1123
add_test_executable(mxs1123.cc mxs1123 mxs1123 LABELS maxscale readwritesplit REPL_BACKEND)

# MXS-1319: Maxscale selecting extra whitespace while loading users
# https://jira.mariadb.org/browse/MXS-1319
add_test_executable(mxs1319.cc mxs1319 replication LABELS MySQLAuth REPL_BACKEND)

# MXS-1418: Removing a server from a service breaks the connection
# https://jira.mariadb.org/browse/MXS-1418
add_test_executable(mxs1418.cc mxs1418 replication LABELS readwritesplit maxscale REPL_BACKEND)

# MXS-1295: MaxScale's readwritesplit router does not take into account the fact
# that stored procedure call may change the value of a user variable
#
# https://jira.mariadb.org/browse/MXS-1295
add_test_executable(mxs1295_sp_call.cc mxs1295_sp_call mxs1295 LABELS maxscale readwritesplit REPL_BACKEND)

# MXS-1457: Deleted servers are not ignored when users are loaded
# https://jira.mariadb.org/browse/MXS-1457
add_test_executable(mxs1457_ignore_deleted.cc mxs1457_ignore_deleted mxs1457_ignore_deleted LABELS REPL_BACKEND)

# MXS-1468: Using dynamic commands to create readwritesplit configs fail after restart
# https://jira.mariadb.org/browse/MXS-1468
add_test_executable(mxs1468.cc mxs1468 mxs1468 LABELS REPL_BACKEND)

# MXS-1503: Test master_reconnection
# https://jira.mariadb.org/browse/MXS-1503
add_test_executable(mxs1503_master_reconnection.cc mxs1503_master_reconnection mxs1503_master_reconnection LABELS readwritesplit REPL_BACKEND)

# Master reconnection with session commands
add_test_executable(mxs1503_queued_sescmd.cc mxs1503_queued_sescmd mxs1503_master_reconnection LABELS readwritesplit REPL_BACKEND)

# Check that no extra slaves are taken into use
add_test_executable(mxs1503_extra_slaves.cc mxs1503_extra_slaves mxs1503_extra_slaves LABELS readwritesplit REPL_BACKEND)

# MXS-1509: Show correct server state for multisource replication
# https://jira.mariadb.org/browse/MXS-1509
add_test_executable(mxs1509.cc mxs1509 mxs1509 LABELS mysqlmon REPL_BACKEND)

# MXS-1516: existing connection don't change routing, even if master switched
# https://jira.mariadb.org/browse/MXS-1516
add_test_executable(mxs1516.cc mxs1516 replication LABELS readconnroute REPL_BACKEND)

# MXS-1549: Optimistic transaction tests
# https://jira.mariadb.org/browse/MXS-1549
add_test_executable(mxs1549_optimistic_trx.cc mxs1549_optimistic_trx mxs1549_optimistic_trx LABELS readwritesplit REPL_BACKEND)

# MXS-1643: Too many monitor events are triggered
# https://jira.mariadb.org/browse/MXS-1643
add_test_executable(mxs1643_extra_events.cc mxs1643_extra_events mxs1643_extra_events LABELS mysqlmon REPL_BACKEND)

# MXS-1653: sysbench failed to initialize w/ MaxScale read/write splitter
# https://jira.mariadb.org/browse/MXS-1653
add_test_executable(mxs1653_ps_hang.cc mxs1653_ps_hang replication LABELS readwritesplit REPL_BACKEND)

# MXS-1677: "Query could not be parsed" errors
# https://jira.mariadb.org/browse/MXS-1677
add_test_executable(mxs1677_temp_table.cc mxs1677_temp_table replication LABELS readwritesplit REPL_BACKEND)

# MXS-1678: Stopping IO thread on relay master causes it to be promoted as master
# https://jira.mariadb.org/browse/MXS-1678
add_test_executable(mxs1678_relay_master.cc mxs1678_relay_master replication LABELS mysqlmon REPL_BACKEND)

# MXS-1743: Maxscale unable to enforce round-robin between read service for Slave
# https://jira.mariadb.org/browse/MXS-1743
add_test_executable(mxs1743_rconn_bitmask.cc mxs1743_rconn_bitmask mxs1743_rconn_bitmask LABELS REPL_BACKEND)

# MXS-1760: With use_sql_variables_in=master, unknown PS errors are logged
# https://jira.mariadb.org/browse/MXS-1760
add_test_executable(mxs1760_use_sql_variables_in.cc mxs1760_use_sql_variables_in mxs1760_use_sql_variables_in LABELS readwritesplit REPL_BACKEND)

# MXS-1773: Failing LOAD DATA LOCAL INFILE confuses readwritesplit
# https://jira.mariadb.org/browse/MXS-1773
add_test_executable(mxs1773_failing_ldli.cc mxs1773_failing_ldli replication LABELS readwritesplit REPL_BACKEND)

# MXS-1776: recursive COM_STMT_EXECUTE execution
# https://jira.mariadb.org/browse/MXS-1776
add_test_executable(mxs1776_ps_exec_hang.cc mxs1776_ps_exec_hang replication LABELS readwritesplit REPL_BACKEND)

# MXS-1787: Crash with PS: CALL p1((SELECT f1()), ?)
# https://jira.mariadb.org/browse/MXS-1787
add_test_executable(mxs1787_call_ps.cc mxs1787_call_ps replication LABELS readwritesplit REPL_BACKEND)

# Modified test for MXS-1787 that checks that slave reconnection works
add_test_executable(mxs1787_slave_reconnection.cc mxs1787_slave_reconnection replication LABELS readwritesplit REPL_BACKEND)

# MXS-1804: request 16M-1 stmt_prepare command packet connect hang
# https://jira.mariadb.org/browse/MXS-1804
add_test_executable(mxs1804_long_ps_hang.cc mxs1804_long_ps_hang replication LABELS readwritesplit REPL_BACKEND)

# MXS-1808: Crash with mysql_stmt_send_long_data
# https://jira.mariadb.org/browse/MXS-1808
add_test_executable(mxs1808_long_data.cc mxs1808_long_data replication LABELS readwritesplit REPL_BACKEND)

# MXS-1824: Debug assertion with two open cursors
# https://jira.mariadb.org/browse/MXS-1824
add_test_executable(mxs1824_double_cursor.cc mxs1824_double_cursor replication LABELS readwritesplit REPL_BACKEND)

# MXS-1828: Multiple LOAD DATA LOCAL INFILE commands in one query cause a hang
# https://jira.mariadb.org/browse/MXS-1828
add_test_executable(mxs1828_double_local_infile.cc mxs1828_double_local_infile replication LABELS readwritesplit REPL_BACKEND)

# MXS-1831: No error on invalid monitor parameter alteration
# https://jira.mariadb.org/browse/MXS-1831
add_test_executable(mxs1831_unknown_param.cc mxs1831_unknown_param replication LABELS REPL_BACKEND)

# MXS-1873: Large session commands cause errors
# https://jira.mariadb.org/browse/MXS-1873
add_test_executable(mxs1873_large_sescmd.cc mxs1873_large_sescmd replication LABELS readwritesplit REPL_BACKEND)

# MXS-1896: LOAD DATA INFILE is mistaken for LOAD DATA LOCAL INFILE
# https://jira.mariadb.org/browse/MXS-1896
add_test_executable(mxs1896_load_data_infile.cc mxs1896_load_data_infile replication LABELS readwritesplit REPL_BACKEND)

# MXS-1899: generated [maxscale] section causes errors
# https://jira.mariadb.org/browse/MXS-1899
add_test_executable(mxs1899_generated_cnf.cc mxs1899_generated_cnf replication LABELS REPL_BACKEND)

# Authentication error testing
add_test_executable(no_password.cc no_password replication LABELS MySQLAuth LIGHT REPL_BACKEND)

# Open and immediatelly close a big number of connections
add_test_executable(open_close_connections.cc open_close_connections replication LABELS maxscale readwritesplit REPL_BACKEND)

# Check if prepared statement works via Maxscale (via RWSplit)
add_test_executable(prepared_statement.cc prepared_statement replication LABELS readwritesplit LIGHT REPL_BACKEND)

# Connect to ReadConn in master mode and check if there is only one backend connection to master
add_test_executable(readconnrouter_master.cc readconnrouter_master replication LABELS readconnroute LIGHT REPL_BACKEND)

# Creates 100 connections to ReadConn in slave mode and check if connections are distributed among all slaves
add_test_executable(readconnrouter_slave.cc readconnrouter_slave replication LABELS readconnroute LIGHT REPL_BACKEND)

# Regex filter test
add_test_executable(regexfilter1.cc regexfilter1 regexfilter1 LABELS regexfilter LIGHT REPL_BACKEND)

# check that Maxscale is reacting correctly on ctrc+c signal and termination does not take ages
add_test_script(run_ctrl_c.sh run_ctrl_c.sh replication LABELS maxscale LIGHT REPL_BACKEND)

# run a set of queries in the loop (see setmix.sql) using Perl client
add_test_script(run_session_hang.sh run_session_hang.sh replication LABELS readwritesplit REPL_BACKEND)

# Checks connections are distributed equaly among backends
add_test_executable(rwsplit_conn_num.cc rwsplit_conn_num repl_lgc LABELS readwritesplit LIGHT REPL_BACKEND)

# Check that there is one connection to Master and one connection to one of slaves
add_test_executable(rwsplit_connect.cc rwsplit_connect replication LABELS readwritesplit LIGHT REPL_BACKEND)

# Test of the read-only mode for readwritesplit when master fails (blocked)
add_test_executable(rwsplit_readonly.cc rwsplit_readonly rwsplit_readonly LABELS readwritesplit REPL_BACKEND)

# Test of the read-only mode for readwritesplit when master fails (blocked), under load
add_test_executable(rwsplit_readonly_stress.cc rwsplit_readonly_stress rwsplit_readonly LABELS readwritesplit HEAVY REPL_BACKEND)

# Test readwritesplit multi-statement handling
add_test_executable(rwsplit_multi_stmt.cc rwsplit_multi_stmt rwsplit_multi_stmt LABELS readwritesplit REPL_BACKEND)

# Test 10.3 SEQUENCE objects
add_test_executable(sequence.cc sequence replication LABELS LIGHT REPL_BACKEND)

# Test 10.1 compound statements
add_test_executable(compound_statement.cc compound_statement replication LABELS LIGHT REPL_BACKEND)

# test for 'max_sescmd_history' and 'connection_timeout' parameters
add_test_executable(session_limits.cc session_limits session_limits LABELS readwritesplit REPL_BACKEND)

# Do short sessions (open conn, short query, close conn) in the loop
add_test_executable(short_sessions.cc short_sessions replication LABELS readwritesplit readconnroute REPL_BACKEND)
add_test_derived(short_sessions_ssl short_sessions replication LABELS readwritesplit readconnroute
        BACKEND_SSL LISTENER_SSL REPL_BACKEND)

# Regression case for crash if 'show monitors' command is issued, but no monitor is not running
add_test_executable(show_monitor_crash.cc show_monitor_crash show_monitor_crash LABELS maxscale REPL_BACKEND)

# Check how Maxscale works in case of one slave failure, only one slave is configured
add_test_executable(slave_failover.cc slave_failover replication.one_slave LABELS readwritesplit REPL_BACKEND)

# Execute queries of different size, check data is the same when accessing via Maxscale and directly to backend
add_test_executable(sql_queries.cc sql_queries replication LABELS readwritesplit REPL_BACKEND)

# Execute queries of different size, check data is the same when accessing via Maxscale and directly to backend, one persistant connection configured
add_test_derived(sql_queries_pers1 sql_queries sql_queries_pers1 LABELS maxscale readwritesplit HEAVY REPL_BACKEND)

# Execute queries of different size, check data is the same when accessing via Maxscale and directly to backend, 10 persistant connections configured
add_test_derived(sql_queries_pers10 sql_queries sql_queries_pers10 LABELS maxscale readwritesplit HEAVY REPL_BACKEND)

# Execute queries of different size, check data is the same when accessing via Maxscale and directly to backend, client ssl is ON
add_test_derived(ssl sql_queries ssl LABELS maxscale readwritesplit REPL_BACKEND LISTENER_SSL)

# Testing slaves who have lost their master and how MaxScale works with them
add_test_executable(stale_slaves.cc stale_slaves stale_slaves LABELS mysqlmon REPL_BACKEND)

# Check temporal tables commands functionality
add_test_executable(temporal_tables.cc temporal_tables replication LABELS readwritesplit REPL_BACKEND)

# Test routing hints (mainly about how readwritesplit deals with them)
add_test_executable(test_hints.cc test_hints hints2 LABELS hintfilter readwritesplit LIGHT REPL_BACKEND)

# start sysbench against RWSplit for infinite execution
add_test_executable_notest(long_sysbench.cc long_sysbench replication LABELS readwritesplit REPL_BACKEND)

# test effect of local_address in configuration file
add_test_executable(local_address.cc local_address local_address LABELS REPL_BACKEND)

# MXS-1628: Security scanner says MaxScale is vulnerable to ancient MySQL vulnerability
# https://jira.mariadb.org/browse/MXS-1628
add_test_executable(mxs1628_bad_handshake.cc mxs1628_bad_handshake replication LABELS REPL_BACKEND)

# MXS-173 throttling filter
add_test_executable(mxs173_throttle_filter.cc mxs173_throttle_filter mxs173_throttle_filter LABELS REPL_BACKEND)

# MXS-1245: Batch execution of queries
add_test_executable(mxs1245_batch_query.cc mxs1245_batch_query replication LABELS REPL_BACKEND readwritesplit)

 # MXS-1889: A single remaining master is valid for readconnroute configured with 'router_options=slave'
 # https://jira.mariadb.org/browse/MXS-1889
add_test_executable(mxs1889.cc mxs1889 mxs1889 LABELS REPL_BACKEND)

# MXS-421 Improved log facility
add_test_executable(mxs421_events.cc mxs421_events mxs421_events LABELS REPL_BACKEND)

# MXS-1926: LOAD DATA LOCAL INFILE interrupted by server shutdown
# https://jira.mariadb.org/browse/MXS-1926
add_test_executable(mxs1926_killed_server.cc mxs1926_killed_server mxs1926_killed_server LABELS readwritesplit REPL_BACKEND)

# MXS-1929: Runtime service creation
# https://jira.mariadb.org/browse/MXS-1929
add_test_executable(mxs1929_service_runtime.cc mxs1929_service_runtime mxs1929_service_runtime LABELS REPL_BACKEND)

# MXS-1929: Runtime filter creation/destruction
# https://jira.mariadb.org/browse/MXS-1929
add_test_executable(mxs1929_filter_runtime.cc mxs1929_filter_runtime mxs1929_filter_runtime LABELS REPL_BACKEND)

# MXS-1929: Create complete configuration at runtime
# https://jira.mariadb.org/browse/MXS-1929
add_test_executable(mxs1929_start_from_scratch.cc mxs1929_start_from_scratch mxs1929_start_from_scratch LABELS REPL_BACKEND)

# MXS-1932: Hidden files are not ignored
# https://jira.mariadb.org/browse/MXS-1932
add_test_executable(mxs1932_hidden_cnf.cc mxs1932_hidden_cnf replication LABELS REPL_BACKEND)

# MXS-1985: MaxScale hangs on concurrent KILL processing
# https://jira.mariadb.org/browse/MXS-1985
add_test_executable(mxs1985_kill_hang.cc mxs1985_kill_hang replication LABELS REPL_BACKEND)

# MXS-2043: Error "The MariaDB server is running with the --read-only option"
#           for "select for update"
# https://jira.mariadb.org/browse/MXS-2043
add_test_executable(mxs2043_select_for_update.cc mxs2043_select_for_update replication LABELS REPL_BACKEND readwritesplit)

# MXS-2054: Hybrid clusters
add_test_executable(mxs2054_hybrid_cluster.cc mxs2054_hybrid_cluster mxs2054_hybrid_cluster LABELS REPL_BACKEND)

# MXS-2111: mysql.user sometimes has SHA1 in authentication_string instead of password
add_test_executable(mxs2111_auth_string.cc mxs2111_auth_string replication LABELS REPL_BACKEND)

# MXS-2115: Automatic version_string detection
add_test_executable(mxs2115_version_string.cc mxs2115_version_string replication LABELS REPL_BACKEND)

# MXS-2273: Introduce server state BEING_DRAINED
add_test_executable(mxs2273_being_drained.cc mxs2273_being_drained mxs2273_being_drained LABELS REPL_BACKEND)

# MXS-2295: COM_CHANGE_USER does not clear out session command history
add_test_executable(mxs2295_change_user_loop.cc mxs2295_change_user_loop mxs2295_change_user_loop LABELS REPL_BACKEND readwritesplit)

# Debug assertion due to double-closed when a slave's response differs from the master
add_test_executable(crash_on_bad_sescmd.cc crash_on_bad_sescmd crash_on_bad_sescmd LABELS readwritesplit REPL_BACKEND)

# MXS-2300: Prune session command history
add_test_executable(mxs2300_history_pruning.cc mxs2300_history_pruning mxs2300_history_pruning LABELS readwritesplit REPL_BACKEND)

# MXS-2326: Routing hints aren't cloned in gwbuf_clone
add_test_executable(mxs2326_hint_clone.cc mxs2326_hint_clone mxs2326_hint_clone LABELS readwritesplit REPL_BACKEND)

# MXS-2313: `rank` functional test
add_test_executable(mxs2313_rank.cc mxs2313_rank mxs2313_rank LABELS readwritesplit REPL_BACKEND)

# MXS-2417: Ignore persisted configs with load_persisted_configs=false
add_test_executable(mxs2417_ignore_persisted_cnf.cc mxs2417_ignore_persisted_cnf mxs2417_ignore_persisted_cnf LABELS REPL_BACKEND)

# MXS-2450: Crash on COM_CHANGE_USER with disable_sescmd_history=true
add_test_executable(mxs2450_change_user_crash.cc mxs2450_change_user_crash mxs2450_change_user_crash LABELS REPL_BACKEND readwritesplit)

# MXS-2414: Block host after repeated authentication failures
add_test_executable(mxs2414_host_blocking.cc mxs2414_host_blocking replication LABELS REPL_BACKEND)

add_subdirectory(authentication)

# Test three jdbc-connectors.
add_test_executable(jdbc_connectors.cc jdbc_connectors replication REPL_BACKEND)

# MXS-2350: On-demand connection creation
add_test_executable(mxs2350_lazy_connect.cc mxs2350_lazy_connect mxs2350_lazy_connect LABELS REPL_BACKEND readwritesplit)

# MXS-2520: Allow master reconnection on reads
add_test_executable(mxs2520_master_read_reconnect.cc mxs2520_master_read_reconnect mxs2520_master_read_reconnect LABELS REPL_BACKEND readwritesplit)

# MXS-2464: Crash in route_stored_query with ReadWriteSplit
add_test_executable(mxs2464_sescmd_reconnect.cc mxs2464_sescmd_reconnect mxs2464_sescmd_reconnect LABELS REPL_BACKEND readwritesplit)

# MXS-2563: Failing debug assertion at rwsplitsession.cc:1129 : m_expected_responses == 0
add_test_executable(mxs2563_concurrent_slave_failure.cc mxs2563_concurrent_slave_failure mxs2563_concurrent_slave_failure LABELS REPL_BACKEND readwritesplit)

# MXS-2521: COM_STMT_EXECUTE maybe return empty result
add_test_executable(mxs2521_double_exec.cc mxs2521_double_exec mxs2521_double_exec LABELS REPL_BACKEND readwritesplit)

# MXS-2572: Add smartrouter tests.
add_test_executable(sr_basics.cc sr_basics sr_basics LABELS REPL_BACKEND)
add_test_executable(smart_query.cc smart_query smart_query LABELS REPL_BACKEND)

# MXS-2490: Direct execution doesn't work with MaxScale
# MXS-3392: Connection reset fails after execute_direct for an unknown table
add_test_executable(ps_execute_direct.cc ps_execute_direct replication LABELS REPL_BACKEND readwritesplit)

# MXS-2609: Maxscale crash in RWSplitSession::retry_master_query()
add_test_executable(mxs2609_history_replay.cc mxs2609_history_replay mxs2609_history_replay LABELS readwritesplit REPL_BACKEND)

# MXS-2621: Incorrect SQL if lower_case_table_names is used.
add_test_executable(mxs2621_lower_case_tables.cc mxs2621_lower_case_tables mxs2621_lower_case_tables LABELS REPL_BACKEND)

# Service-to-Service routing with readwritesplit
add_test_executable(sts_readwritesplit.cc sts_readwritesplit sts_readwritesplit LABELS readwritesplit REPL_BACKEND)

# Service-to-Service routing with readconnroute
add_test_executable(sts_readconnroute.cc sts_readconnroute sts_readconnroute LABELS readconnroute REPL_BACKEND)

# Service-to-Service routing with smartrouter
add_test_executable(sts_smartrouter.cc sts_smartrouter sts_smartrouter LABELS smartrouter REPL_BACKEND)

# Service-to-Service routing runtime configuration
add_test_executable(sts_config.cc sts_config sts_config LABELS REPL_BACKEND)

# Test that masking filter can handle multi-statements.
add_test_executable(mxs1719.cc mxs1719 mxs1719 LABELS masking REPL_BACKEND)

# MXS-2057 systemd watchdog
add_test_executable(mxs2057_systemd_watchdog.cc mxs2057_systemd_watchdog mxs2057_systemd_watchdog LABELS REPL_BACKEND)

# Tries prepared stmt 'SELECT 1,1,1,1...." with different nu,ber of '1'
add_test_executable(mxs314.cc mxs314 replication LABELS readwritesplit LIGHT REPL_BACKEND)

# Basic mirror router test
add_test_executable(test_mirror.cc test_mirror test_mirror LABELS mirror LIGHT REPL_BACKEND)

# Test connection_keepalive
add_test_executable(connection_keepalive.cc connection_keepalive connection_keepalive LABELS readwritesplit REPL_BACKEND)

# MXS-2729 Thread rebalancing
add_test_executable(mxs2729_rebalance.cc mxs2729_rebalance replication LABELS REPL_BACKEND)

# MXS-2750: Test COM_STMT_EXECUTE metadata addition
# MXS-3565: Target selection for COM_STMT_EXECUTION without metadata isn't done correctly
add_test_executable(mxs2750_com_stmt_exec.cc mxs2750_com_stmt_exec replication LABELS readwritesplit REPL_BACKEND)

# MXS-2878: Verify that TLS is required
add_test_executable(mxs2878_monitor_ssl.cc mxs2878_monitor_ssl mxs2878_monitor_ssl LABELS REPL_BACKEND)

# MXS-2939: Test that session commands trigger a reconnection
add_test_executable(mxs2939_sescmd_reconnect.cc mxs2939_sescmd_reconnect mxs2939_sescmd_reconnect LABELS REPL_BACKEND readwritesplit)

# MXS-2145 and MXS-2623
add_test_executable(connection_init_queries.cc connection_init_queries connection_init_queries LABELS REPL_BACKEND)

# MXS-2919: Slaves with broken replication should not be used
add_test_executable(mxs2919_broken_slaves.cc mxs2919_broken_slaves mxs2919_broken_slaves LABELS REPL_BACKEND readwritesplit)

# MXS-3218: Crash with LOAD DATA LOCAL INFILE
add_test_executable(mxs3218_ldli_crash.cc mxs3218_ldli_crash replication LABELS REPL_BACKEND)

# MXS-3128: Listener SSL alteration test
add_test_executable(mxs3128_listener_ssl.cc mxs3128_listener_ssl replication LABELS REPL_BACKEND)

# MXS-3220: Crash on master reconnection with session command
add_test_executable(mxs3220_reconnect_crash.cc mxs3220_reconnect_crash mxs3220_reconnect_crash LABELS REPL_BACKEND readwritesplit)

# MXS-3184: FOUND_ROWS with prepared statements
add_test_executable(mxs3184_ps_found_rows.cc mxs3184_ps_found_rows replication LABELS REPL_BACKEND readwritesplit)

# MXS-3108: Alter session test
add_test_executable(mxs3108_alter_session.cc mxs3108_alter_session mxs3108_alter_session LABELS REPL_BACKEND)

# MXS-3339: Hang with COM_STMT_CLOSE in sescmd history
add_test_executable(mxs3339_stmt_close_hang.cc mxs3339_stmt_close_hang mxs3339_stmt_close_hang LABELS REPL_BACKEND readwritesplit)

# MXS-3353: Tee filter loses queries
# Also covers MXS-3365: Missing match setting in filter(s) results in no match at all
add_test_executable(mxs3353_tee_lost_inserts.cc mxs3353_tee_lost_inserts mxs3353_tee_lost_inserts LABELS REPL_BACKEND readwritesplit)

# MXS-3454: PS inside trx with transaction_replay fails
add_test_executable(mxs3454_ps_in_trx.cc mxs3454_ps_in_trx mxs3454_ps_in_trx LABELS REPL_BACKEND readwritesplit)

# MXS-3459: LOAD DATA LOCAL INFILE fails with binary data
add_test_executable(mxs3459_binary_ldli.cc mxs3459_binary_ldli replication LABELS REPL_BACKEND)

# MXS-3462: Service to service routing with `cluster` doesn't work
add_test_executable(mxs3462_sts_update.cc mxs3462_sts_update mxs3462_sts_update LABELS REPL_BACKEND)

# MXS-3472: Transaction replay is not attempted again if session commands fail
add_test_executable(mxs3472_trx_master_failure.cc mxs3472_trx_master_failure mxs3472_trx_master_failure LABELS REPL_BACKEND readwritesplit)

# MXS-3479: Disabling maxlog doesn't fully prevent it from being written to
add_test_executable(mxs3479_no_maxlog.cc mxs3479_no_maxlog mxs3479_no_maxlog LABELS REPL_BACKEND readwritesplit)

# MXS-3536: max_slave_connections=0 doesn't work as expected
add_test_executable(mxs3536_rwsplit_no_slaves.cc mxs3536_rwsplit_no_slaves mxs3536_rwsplit_no_slaves LABELS REPL_BACKEND readwritesplit)

# MXS-3588: Packet with length of 0xfffffb is treated as a large packet
add_test_executable(mxs3588_almost_large_packet.cc mxs3588_almost_large_packet replication LABELS REPL_BACKEND readwritesplit)

# MXS-3617: Large batch causes response packets to be lost
add_test_executable(mxs3617_lost_packets.cc mxs3617_lost_packets replication LABELS REPL_BACKEND readconnroute)

# MXS-3623: Race condition in COM_CHANGE_USER handling
add_test_executable(mxs3623_persistent_change_user.cc mxs3623_persistent_change_user mxs3623_persistent_change_user LABELS REPL_BACKEND readwritesplit)

# MXS-3458: Prepared statements fail if strict_sp_calls is enabled
add_test_executable(mxs3458_ps_with_strict_sp.cc mxs3458_ps_with_strict_sp mxs3458_ps_with_strict_sp LABELS REPL_BACKEND readwritesplit)

# Qlafilter test
add_test_executable(test_qlafilter.cc test_qlafilter test_qlafilter LABELS REPL_BACKEND)

# MXS-4410: "USE db" does not update the database logged to the qla-log.
add_test_executable(mxs4410_db_not_logged.cc mxs4410_db_not_logged mxs4410_db_not_logged LABELS REPL_BACKEND)

# MXS-3769: Support for SET TRANSACTION
add_test_executable(mxs3769_set_transaction.cc mxs3769_set_transaction mxs3769_set_transaction LABELS REPL_BACKEND readwritesplit)

# MXS-3770: Bundled connector plugins
add_test_executable(mxs3770_connector_plugins.cc mxs3770_connector_plugins mxs3770_connector_plugins LABELS REPL_BACKEND LIGHT)

# MXS-3782: session_track_trx_state causes incorrect routing of SELECT
add_test_executable(mxs3782_session_track_trx_state.cc mxs3782_session_track_trx_state mxs3782_session_track_trx_state LABELS REPL_BACKEND readwritesplit)

# MXS-3796: Hang with readconnroute and large-ish queries
add_test_executable(mxs3796_rcr_hang.cc mxs3796_rcr_hang replication LABELS REPL_BACKEND)

# MXS-3803: Routing hints override transaction target
add_test_executable(mxs3803_trx_replay_hints.cc mxs3803_trx_replay_hints mxs3803_trx_replay_hints LABELS REPL_BACKEND readwritesplit)

# MXS-3881: LOAD DATA LOCAL INFILE inside of a transaction with transaction_replay enabled
add_test_executable(mxs3881_ldli_trx_replay.cc mxs3881_ldli_trx_replay mxs3881_ldli_trx_replay LABELS REPL_BACKEND readwritesplit)

# MXS-3894: Test for transaction_replay_checksum
add_test_executable(mxs3894_trx_checksum.cc mxs3894_trx_checksum mxs3894_trx_checksum LABELS REPL_BACKEND readwritesplit)

# MXS-3920: Unicode characters in database names don't work
add_test_executable(mxs3920_unicode_db.cc mxs3920_unicode_db replication LABELS REPL_BACKEND)

# MXS-3959: Transaction replay doesn't reset transaction on implicit commit
add_test_executable(mxs3959_implicit_commit.cc mxs3959_implicit_commit mxs3959_implicit_commit LABELS REPL_BACKEND readwritesplit)

# MXS-3924: Session commands aren't retried when delayed_retry is enabled
add_test_executable(mxs3924_sescmd_retry.cc mxs3924_sescmd_retry mxs3924_sescmd_retry LABELS REPL_BACKEND readwritesplit)

add_test_executable_ex(NAME idle_pool_max_conns SOURCE idle_pool_max_conns.cc CONFIG idle_pool_max_conns.cnf
        VMS repl_backend)

# Auto_tune
add_test_executable(auto_tune.cc auto_tune auto_tune LABELS REPL_BACKEND)

# MXS-4194: QC cache size keeps growing
add_test_executable(mxs4194_qc_cache_size.cc mxs4194_qc_cache_size mxs4194_qc_cache_size LABELS REPL_BACKEND readwritesplit)

# MXS-4232: Retain and use service password if new does not work
add_test_executable(mxs4232_retain_service_password.cc mxs4232_retain_service_password mxs4232_retain_service_password LABELS REPL_BACKEND)

# MXS-4420: Pipeline read-only transactions are not handled correctly
add_test_executable(mxs4420_pipelined_ro_trx.cc mxs4420_pipelined_ro_trx mxs4420_pipelined_ro_trx LABELS REPL_BACKEND readwritesplit)

# MXS-4440: connection_keepalive doesn't work with long queries
add_test_executable(mxs4440_long_query_keepalive.cc mxs4440_long_query_keepalive mxs4440_long_query_keepalive LABELS REPL_BACKEND readwritesplit)

# MXS-4474: MaxScale hangs when worker writes messages to itself
add_test_executable(mxs4474_worker_messages.cc mxs4474_worker_messages replication LABELS REPL_BACKEND readwritesplit)

# MXS-4488: MaxScale hangs when client sends garbage
add_test_executable(mxs4488_garbage.cc mxs4488_garbage mxs4488_garbage LABELS REPL_BACKEND readwritesplit)

# MXS-4505: transaction_replay_safe_commit=true should prevent about-to-commit transaction from being replayed
add_test_executable(mxs4505_trx_safe_replay.cc mxs4505_trx_safe_replay mxs4505_trx_safe_replay LABELS REPL_BACKEND readwritesplit)

# MXS-4522: Loss of temporary tables on reconnection is ignored
add_test_executable(mxs4522_tmp_table_reconnect.cc mxs4522_tmp_table_reconnect mxs4522_tmp_table_reconnect LABELS REPL_BACKEND readwritesplit)

# MXS-4540: transaction_replay_retry_on_mismatch=true leads to infinite replays
add_test_executable(mxs4540_mismatch_replay.cc mxs4540_mismatch_replay mxs4540_mismatch_replay LABELS REPL_BACKEND readwritesplit)

# MXS-4549: Replay queries with partially returned results
add_test_executable(mxs4549_splice_results.cc mxs4549_splice_results mxs4549_splice_results LABELS REPL_BACKEND readwritesplit)

# MXS-4615: Partially executed multistatements aren't treated as partial results
add_test_executable(mxs4615_partial_multistmt.cc mxs4615_partial_multistmt mxs4615_partial_multistmt LABELS REPL_BACKEND readwritesplit)

# MXS-4635: Connection metadata
add_test_executable(mxs4635_custom_sysvars.cc mxs4635_custom_sysvars replication LABELS REPL_BACKEND readwritesplit)

# MXS-4826: Forbid replication through MaxScale with allow_replication=false
add_test_executable(mxs4826_allow_replication.cc mxs4826_allow_replication mxs4826_allow_replication LABELS REPL_BACKEND readwritesplit)

# MXS-4847: Crash on `maxctrl show sessions`
add_test_executable(mxs4847_diagnostics_crash.cc mxs4847_diagnostics_crash replication LABELS REPL_BACKEND)

# MXS-4858: Crash on dump_last_statements=on_close
add_test_executable(mxs4858_dump_on_close.cc mxs4858_dump_on_close mxs4858_dump_on_close LABELS REPL_BACKEND)

# MXS-4881: Test commandline path handling
add_test_executable(basedir.cc basedir replication LABELS REPL_BACKEND)

# MXS-4978: START TRANSACTION READ ONLY is routed to a failed server
add_test_executable(mxs4978_wrong_ro_trx_target.cc mxs4978_wrong_ro_trx_target replication LABELS REPL_BACKEND readwritesplit)

# MXS-5032: Simple SET inside a PS is not executed on history replay
add_test_executable(mxs5032_set_in_ps.cc mxs5032_set_in_ps mxs5032_set_in_ps LABELS REPL_BACKEND readwritesplit)

# MXS-5063: Fake events don't respect writeq throttling
add_test_executable(mxs5063_big_resultset.cc mxs5063_big_resultset mxs5063_big_resultset LABELS REPL_BACKEND readwritesplit)

# MXS-5085: max_slave_connections=0 creates a slave connection after switchover
add_test_executable(mxs5085_too_many_slaves.cc mxs5085_too_many_slaves mxs5085_too_many_slaves LABELS REPL_BACKEND readwritesplit)

# environment variable substitution and admin_secure_gui
add_test_executable_ex(NAME env_var_substitution SOURCE env_var_substitution.cc
        CONFIG env_var_substitution.cnf VMS repl_backend)

############################################
# END: Normal tests                        #
############################################

############################################
# BEGIN: backend SSL tests                 #
############################################

add_test_derived(sql_queries_ssl sql_queries ssl LABELS readwritesplit REPL_BACKEND BACKEND_SSL LISTENER_SSL)

# MXS-3128: Server SSL alteration test
add_test_executable(mxs3128_server_ssl.cc mxs3128_server_ssl replication LABELS REPL_BACKEND BACKEND_SSL)

############################################
# END: backend SSL  tests                  #
############################################

############################################
# BEGIN: avrorouter tests                  #
############################################

add_test_executable(avro.cc avro avro LABELS avrorouter LIGHT BREAKS_REPL REPL_BACKEND)
add_test_executable(avro_alter.cc avro_alter avro LABELS avrorouter LIGHT BREAKS_REPL REPL_BACKEND)

# Test of CDC protocol (avro listener)
add_test_executable(cdc_client.cc cdc_client avro LABELS avrorouter BREAKS_REPL REPL_BACKEND)

# MXS-1543: Avrorouter doesn't detect MIXED or STATEMENT format replication
# https://jira.mariadb.org/browse/MXS-1543
add_test_executable(mxs1543.cc mxs1543 avro LABELS avrorouter REPL_BACKEND)

# MXS-1949: Warning for user load failure logged even when service has no users
# https://jira.mariadb.org/browse/MXS-1949
add_test_executable(mxs1949_warn_user_injection.cc mxs1949_warn_user_injection avro LABELS REPL_BACKEND)

# MXS-2106: NULL values with avrorouter
add_test_executable(mxs2106_avro_null.cc mxs2106_avro_null avro LABELS avrorouter REPL_BACKEND)

# MXS-1687: Avrorouter HA test (tests the same mechanism that kafkacdc uses)
add_test_executable(mxs1687_avro_ha.cc mxs1687_avro_ha mxs1687_avro_ha LABELS avrorouter REPL_BACKEND)

# MXS-3580: Avrorouter multidomain gtid support.
add_test_executable(avro_gtid.cc avro_gtid avro_gtid LABELS avrorouter REPL_BACKEND)

# MXS-4010: Avrorouter file rotation
add_test_executable(mxs4010_avro_rotate.cc mxs4010_avro_rotate mxs4010_avro_rotate LABELS avrorouter REPL_BACKEND)

############################################
# END: avrorouter tests                    #
############################################

############################################
# BEGIN: Galera tests                      #
############################################

# Crash in case of backend node in Galera cluster stopping and then reconnect to Maxscale
add_test_executable(bug676.cc bug676 galera LABELS galeramon GALERA_BACKEND)

# Galera node priority test. Also tests MXS-3826 and MXS-3532.
add_test_executable(galera_priority.cc galera_priority galera_priority LABELS galeramon LIGHT GALERA_BACKEND)

# INSERT extremelly big number of rows
add_test_executable(lots_of_rows.cc lots_of_rows galera LABELS readwritesplit HEAVY GALERA_BACKEND)

# Prepearing and execution statements in the loop
add_test_executable(mxs244_prepared_stmt_loop.cc mxs244_prepared_stmt_loop galera LABELS readwritesplit readconnroute LIGHT GALERA_BACKEND)

# Playing with blocking and unblocking nodes under INSERT load
add_test_executable(mxs564_big_dump.cc mxs564_big_dump galera_mxs564 LABELS readwritesplit readconnroute GALERA_BACKEND)

# MXS-1476: priority value ignored when a Galera node rejoins with a lower wsrep_local_index than current master
# https://jira.mariadb.org/browse/MXS-1476
add_test_executable(mxs1476.cc mxs1476 mxs1476 LABELS galeramon GALERA_BACKEND)

# MXS-1751: Maxscale crashes when certain config is in play (with nodes down)
# https://jira.mariadb.org/browse/MXS-1751
add_test_executable(mxs1751_available_when_donor_crash.cc mxs1751_available_when_donor_crash mxs1751_available_when_donor_crash LABELS galeramon GALERA_BACKEND)

# Persistant connection test. Also MXS-3265.
add_test_executable(pers_01.cc pers_01 pers_01 LABELS maxscale REPL_BACKEND readwritesplit)

# Test with extremely big blob inserting/selecting with > 16 mb data blocks
add_test_executable(mxs1110_16mb.cc mxs1110_16mb mxs1110_16mb LABELS readwritesplit readconnroute
        REPL_BACKEND)
add_test_derived(mxs1110_16mb_ssl mxs1110_16mb mxs1110_16mb LABELS readwritesplit readconnroute
        REPL_BACKEND LISTENER_SSL BACKEND_SSL)

# A set of MariaDB server tests executed against Maxscale RWSplit (Galera backend)
add_test_script(mariadb_tests_hartmut_galera.sh mariadb_tests_hartmut.sh galera_hartmut LABELS readwritesplit GALERA_BACKEND)

# Crash with Galera and backend restart when persistant cfonnections are in use
add_test_derived(mxs361 pers_02 mxs361 mxs361 LABELS maxscale REPL_BACKEND GALERA_BACKEND)

 # MXS-1585: Crash in MaxScale 2.1.12
 # https://jira.mariadb.org/browse/MXS-1585
add_test_executable(mxs1585.cc mxs1585 mxs1585 LABELS GALERA_BACKEND)

# Test big number of opened connections with persistent connections configured
add_test_executable(pers_02.cc pers_02 pers_01 LABELS maxscale REPL_BACKEND readwritesplit)

# Test of external script execution. Includes MXS-2723.
add_test_executable(script.cc script script LABELS maxscale REPL_BACKEND GALERA_BACKEND)

# MXS-2441: Add support for read-only slaves to galeramon
add_test_executable(mxs2441_galera_slaves.cc mxs2441_galera_slaves mxs2441_galera_slaves LABELS REPL_BACKEND GALERA_BACKEND)

# MXS-3827: admin audit
add_test_executable(admin_audit.cc admin_audit admin_audit LABELS LIGHT CONFIG)

# MXS-4191: admin hosts
add_test_executable_ex(NAME admin_hosts SOURCE admin_hosts.cc CONFIG admin_hosts.cnf VMS repl_backend)

############################################
# END: Galera tests                        #
############################################


##############################################
# BEGIN: DUMMY test to create GUI demo setup #
##############################################

add_test_executable_notest(gui_demo.cc gui_demo gui_demo LABELS gui_demo REPL_BACKEND)

##############################################
# END: DUMMY test to create GUI demo setup   #
##############################################


###############################
# DO NOT ADD TESTS AFTER THIS #
###############################

# The core testing library
add_linebreaks(TEST_DEFINITIONS TEST_DEFINITIONS)
configure_file(maxtest/src/test_info.cc.in maxtest/src/test_info.cc @ONLY)
add_subdirectory(maxtest)
